import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// import indexPage from '../views/index.vue'
// import loginPage from '../views/login.vue'

const routes = [
  { path: '/', redirect: './index' },///进入APP默认页面
  {
    path: '/index',
    component: () => import('../views/index'),
    redirect: '/index/banners',
    meta: { title: '首页' },
    children: [
      {
        path: 'banners',
        meta: { title: '轮播图管理' },
        component: () => import('../views/shouye/banner'),
        beforeEnter: (to, from, next) => {
          console.log('独享守卫')
          next()
        }

      },
      { path: 'category', meta: { title: '分类区管理' }, component: () => import('../views/shouye/category') },
      { path: 'recomend', meta: { title: '为你推荐管理' }, component: () => import('../views/shouye/recomend') }
    ]
  },
  {
    path: '/index',
    component: () => import('../views/index'),
    redirect: '/index/brands',
    meta: { title: '品牌' },
    children: [
      {
        path: 'brands',
        meta: { title: '品牌管理' },
        component: () => import('../views/shangping/brands'),
        beforeEnter: (to, from, next) => {
          console.log('独享守卫')
          next()
        }

      },
      { path: 'sort', meta: { title: '分类管理' }, component: () => import('../views/shangping/sort') },
      { path: 'brands', meta: { title: '品牌管理' }, component: () => import('../views/shangping/brands') },
      { path: 'good', meta: { title: '单品管理' }, component: () => import('../views/shangping/good') },
      { path: 'goods', meta: { title: '商品管理' }, component: () => import('../views/shangping/goods') }
    ]
  },
  {
    path: '/index',
    component: () => import('../views/index'),
    redirect: '/index/news',
    meta: { title: '新闻' },
    children: [
      {
        path: 'news',
        meta: { title: '新闻管理' },
        component: () => import('../views/xinwen/news'),
        beforeEnter: (to, from, next) => {
          console.log('独享守卫')
          next()
        }

      },
      { path: 'news', meta: { title: '新闻管理' }, component: () => import('../views/xinwen/news') }
    ]
  },
  { path: '/login', component: () => import('../views/login') },
]

const router = new VueRouter({
  routes // `routes: routes` 的缩写
})

// router.beforeEach((to,from,next) => {
//   console.log(to,from)
//   next()
// })

export default router